package logic

import (
	"context"
	"errors"
	"gorm.io/gorm"
	"user-srv/model/mysql"

	"user-srv/internal/svc"
	"user-srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetIdCardInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetIdCardInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetIdCardInfoLogic {
	return &GetIdCardInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetIdCardInfoLogic) GetIdCardInfo(in *user.GetIdCardInfoRequest) (*user.GetIdCardInfoResponse, error) {
	// todo: add your logic here and delete this line
	r := mysql.RealAuth{
		IdCard: in.IdCard,
	}
	err := r.GetIdCardInfo()
	if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
		return nil, errors.New("查询实名信息失败")
	}
	return &user.GetIdCardInfoResponse{
		UserId:   r.UserId,
		ID:       int64(r.ID),
		RealName: r.RealName,
		IdCard:   r.IdCard,
	}, nil
}
